from selenium.webdriver.common.by import By

from page_objects.base_page import BasePage


class LoginPage2(BasePage):
    page_url = '/accounts/login/'
    username_input_loc = (By.ID, 'id_login')
    password_input_loc = (By.ID, 'id_password')
    captcha_input_loc = (By.ID, 'id_captcha_1')
    login_button_loc = (By.CLASS_NAME, 'primaryAction')
    login_success_msg = (By.CLASS_NAME, 'alert.success.alert-dismissible')

    def input_username(self, id_login):
        # *:拆开元组，把每个元素作为一个方法的参数传入
        # self.driver.find_element(*self.username_input_loc).send_keys('1464233801@qq.com')
        self.send_keys(*self.username_input_loc, id_login)

    def input_password(self, id_password):
        # self.driver.find_element(*self.password_input_loc).send_keys('bj0304BJA')
        self.send_keys(*self.password_input_loc, id_password)

    def input_captcha(self, id_captcha_1):
        # self.driver.find_element(*self.captcha_input_loc).send_keys('passed')
        self.send_keys(*self.captcha_input_loc, id_captcha_1)

    def click_button(self):
        # self.driver.find_element(*self.login_button_loc).click()
        self.click(*self.login_button_loc)

    def login(self, id_login='1464233801@qq.com', id_password='bj0304BJA', id_captcha_1='passed',
              expected='以 lllljl..身份成功登录'):
        self.open()
        self.input_username(id_login)
        self.input_password(id_password)
        self.input_captcha(id_captcha_1)
        self.click_button()
        self.assert_page_contains_test(expected)
